home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 028a / unarj221.exe / UNARJ.H < prev   
C/C++ Source or Header  |  1991-09-06  |  12KB  |  398 lines

  1. /* UNARJ.H, UNARJ, R JUNG, 08/31/91
  2.  * Include file
  3.  * Copyright (c) 1990 by Robert K Jung.  All rights reserved.
  4.  *
  5.  *   This code may be freely used in programs that are NOT ARJ archivers
  6.  *   (both compress and extract ARJ archives).
  7.  *
  8.  *   If you wish to distribute a modified version of this program, you
  9.  *   MUST indicate that it is a modified version both in the program and
  10.  *   source code.
  11.  *
  12.  *   If you modify this program, I would appreciate a copy of the new
  13.  *   source code.  I am holding the copyright on the source code, so
  14.  *   please do not delete my name from the program files or from the
  15.  *   documentation.
  16.  *
  17.  * Modification history:
  18.  * Date      Programmer  Description of modification.
  19.  * 04/05/91  R. Jung     Rewrote code.
  20.  * 04/23/91  M. Adler    Portabilized.
  21.  * 04/29/91  R. Jung     Added volume label support.
  22.  * 05/30/91  R. Jung     Added SEEK_END definition.
  23.  * 06/03/91  R. Jung     Changed arguments in get_mode_str() and
  24.  *                       set_ftime_mode().
  25.  * 06/28/91  R. Jung     Added new HOST OS numbers.
  26.  * 07/08/91  R. Jung     Added default_case_path() and strlower().
  27.  * 07/21/91  R. Jung     Fixed #endif _QC comment.
  28.  * 08/27/91  R. Jung     Added #ifdef for COHERENT.
  29.  * 09/01/91  R. Jung     Added new host names.
  30.  *
  31.  */
  32.  
  33. #ifndef _ARH_DEF_
  34. #define _ARH_DEF_
  35.  
  36. /* Use prototypes and ANSI libraries if __STDC__ */
  37. #ifdef __STDC__
  38. #  define MODERN
  39. #endif /* __STDC__ */
  40.  
  41. /* Do not use prototypes for COHERENT */
  42. #ifdef COHERENT
  43. #  undef  MODERN
  44. #  define KEEP_WINDOW
  45. #endif /* COHERENT */
  46.  
  47. /* Use prototypes and ANSI libraries if __TURBOC__ */
  48. #ifdef __TURBOC__
  49. #  define MODERN
  50. #endif /* __TURBOC__ */
  51.  
  52. /* Use prototypes and ANSI libraries if _QC */
  53. #ifdef _QC
  54. #  define MODERN
  55. #endif /* _QC */
  56.  
  57. /* Use prototypes and ANSI libraries if _OS2 */
  58. #ifdef _OS2
  59. #  define MODERN
  60. #endif /* _OS2 */
  61.  
  62. /* Used to remove arguments in function prototypes for non-ANSI C */
  63. #ifdef MODERN
  64. #  define OF(a) a
  65. #else /* !MODERN */
  66. #  define OF(a) ()
  67. #endif /* ?MODERN */
  68.  
  69. #ifdef MODERN
  70.    typedef void voidp;
  71. #else /* !MODERN */
  72. #  define void int
  73.    typedef char voidp;
  74. #endif /* ?MODERN */
  75.  
  76. #include <stdio.h>
  77. #ifdef MODERN
  78. #  include <limits.h>
  79. #else /* !MODERN */
  80. #  ifndef UCHAR_MAX
  81. #    define UCHAR_MAX (255)
  82. #  endif
  83. #  ifndef CHAR_BIT
  84. #    define CHAR_BIT  (8)
  85. #  endif
  86. #  ifndef LONG_MAX
  87. #    define LONG_MAX  (0x7FFFFFFFL)
  88. #  endif
  89. #endif /* ?MODERN */
  90.  
  91. #ifndef SEEK_SET
  92. #  define SEEK_SET 0
  93. #endif
  94.  
  95. #ifndef SEEK_CUR
  96. #  define SEEK_CUR 1
  97. #endif
  98.  
  99. #ifndef SEEK_END
  100. #  define SEEK_END 2
  101. #endif
  102.  
  103. typedef unsigned char  uchar;   /*  8 bits or more */
  104. typedef unsigned int   uint;    /* 16 - 32 bits or more */
  105. typedef unsigned short ushort;  /* 16 bits or more */
  106. typedef unsigned long  ulong;   /* 32 bits or more */
  107.  
  108. #define USHRT_BIT   (CHAR_BIT * sizeof(ushort))
  109.  
  110. /* ********************************************************* */
  111. /* Environment definitions (implementation dependent)        */
  112. /* ********************************************************* */
  113.  
  114. #ifdef _QC
  115. #define __MSDOS__
  116. #endif
  117.  
  118. #ifdef __MSDOS__
  119. #define OS                  0
  120. #define PATH_SEPARATORS     "\\:"
  121. #define PATH_CHAR           '\\'
  122. #define MAXSFX              25000L
  123. #define ARJ_SUFFIX          ".ARJ"
  124. #endif
  125.  
  126. #ifdef _OS2
  127. #define OS                  0           /* ??? */
  128. #define PATH_SEPARATORS     "\\:"
  129. #define PATH_CHAR           '\\'
  130. #define SWITCH_CHARS        "-/"
  131. #define MAXSFX              25000L
  132. #define ARJ_SUFFIX          ".ARJ"
  133. #endif
  134.  
  135. #ifdef __CI
  136. #define PRIME               1
  137. #define OS                  1
  138. #define PATH_SEPARATORS     ">"
  139. #define PATH_CHAR           '>'
  140. #define FIX_PARITY(c)       c |= ~ASCII_MASK
  141. #define DEFAULT_DIR         "*>"
  142. #define ARJ_SUFFIX          ".ARJ"
  143. #endif
  144.  
  145. /* Error levels */
  146.  
  147. #ifndef ERROR_DEFINES
  148.  
  149. #define ERROR_OK        0       /* success */
  150. #define ERROR_WARN      1       /* minor problem (file not found) */
  151. #define ERROR_FAIL      2       /* fatal error */
  152. #define ERROR_CRC       3       /* CRC error */
  153. #define ERROR_SECURE    4       /* ARJ security invalid or not found */
  154. #define ERROR_WRITE     5       /* disk full */
  155. #define ERROR_OPEN      6       /* can't open file */
  156. #define ERROR_USER      7       /* user specified bad parameters */
  157. #define ERROR_MEMORY    8       /* not enough memory */
  158.  
  159. #endif
  160.  
  161. #ifndef MAXSFX              /* size of self-extracting prefix */
  162. #define MAXSFX              500000L
  163. #endif
  164. #ifndef FNAME_MAX
  165. #define FNAME_MAX           512
  166. #endif
  167. #ifndef SWITCH_CHARS
  168. #define SWITCH_CHARS        "-"
  169. #endif
  170. #ifndef FIX_PARITY
  171. #define FIX_PARITY(c)       c &= ASCII_MASK
  172. #endif
  173. #ifndef ARJ_SUFFIX
  174. #define ARJ_SUFFIX          ".arj"
  175. #endif
  176. #ifndef ARJ_DOT
  177. #define ARJ_DOT             '.'
  178. #endif
  179. #ifndef DEFAULT_DIR
  180. #define DEFAULT_DIR         ""
  181. #endif
  182. #ifndef OS
  183. #define OS                  2
  184. #endif
  185. #ifndef PATH_SEPARATORS
  186. #define PATH_SEPARATORS     "/"
  187. #endif
  188. #ifndef PATH_CHAR
  189. #define PATH_CHAR           '/'
  190. #endif
  191.  
  192. /* ********************************************************* */
  193. /* end of environmental defines                              */
  194. /* ********************************************************* */
  195.  
  196. /* ********************************************************* */
  197. /*
  198.  * Structure of archive block (low order byte first):
  199.  *
  200.  *  2  header id (comment and local file) = 0xEA60 or 60000U
  201.  *  2  basic header size (from 'first_hdr_size' thru 'comment' below)
  202.  *           = first_hdr_size + strlen(filename) + 1 + strlen(comment) + 1
  203.  *           = 0 if end of archive
  204.  *
  205.  *  1  first_hdr_size (size up to 'extra data')
  206.  *  1  archiver version number
  207.  *  1  minimum archiver version to extract
  208.  *  1  host OS   (0 = MSDOS, 1 = PRIMOS, 2 = UNIX, 3 = AMIGA, 4 = MAC-OS)
  209.  *               (5 = OS/2, 6 = APPLE GS, 7 = ATARI ST, 8 = NEXT)
  210.  *               (9 = VAX VMS)
  211.  *  1  arj flags (0x01 = GARBLED_FLAG, 0x02 = RESERVED)
  212.  *               (0x04 = VOLUME_FLAG,  0x08 = EXTFILE_FLAG)
  213.  *               (0x10 = PATHSYM_FLAG)
  214.  *  1  method    (0 = stored, 1 = compressed most ... 4 compressed fastest)
  215.  *  1  file type (0 = binary, 1 = text, 2 = comment header)
  216.  *               (3 = directory, 4 = volume label)
  217.  *  1  reserved
  218.  *  4  date time stamp modified
  219.  *  4  compressed size
  220.  *  4  original size
  221.  *  4  original file's CRC
  222.  *  2  entryname position in filename
  223.  *  2  file access mode
  224.  *  2  host data
  225.  *  ?  extra data
  226.  *     4 bytes for extended file position
  227.  *
  228.  *  ?  filename (null-terminated)
  229.  *  ?  comment  (null-terminated)
  230.  *
  231.  *  4  basic header CRC
  232.  *
  233.  *  2  1st extended header size (0 if none)
  234.  *  ?  1st extended header
  235.  *  4  1st extended header's CRC (not present if 0 extended header size)
  236.  *  ...
  237.  *  ?  compressed file
  238.  *
  239.  * ********************************************************* */
  240.  
  241. /* ********************************************************* */
  242. /*                                                           */
  243. /*     Time stamp format:                                    */
  244. /*                                                           */
  245. /*      31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16      */
  246. /*     |<---- year-1980 --->|<- month ->|<--- day ---->|     */
  247. /*                                                           */
  248. /*      15 14 13 12 11 10  9  8  7  6  5  4  3  2  1  0      */
  249. /*     |<--- hour --->|<---- minute --->|<- second/2 ->|     */
  250. /*                                                           */
  251. /* ********************************************************* */
  252.  
  253. #define CODE_BIT          16
  254.  
  255. #define NULL_CHAR       '\0'
  256. #define MAXMETHOD          4
  257.  
  258. #define ARJ_VERSION        3
  259. #define ARJ_X_VERSION      3    /* decoder version */
  260. #define ARJ_X1_VERSION     1
  261. #define DEFAULT_METHOD     1
  262. #define DEFAULT_TYPE       0    /* if type_sw is selected */
  263. #define HEADER_ID     0xEA60
  264. #define HEADER_ID_HI    0xEA
  265. #define HEADER_ID_LO    0x60
  266. #define FIRST_HDR_SIZE    30
  267. #define FIRST_HDR_SIZE_V  34
  268. #define COMMENT_MAX     2048
  269. #define HEADERSIZE_MAX   (FIRST_HDR_SIZE + 10 + FNAME_MAX + COMMENT_MAX)
  270. #define BINARY_TYPE        0    /* This must line up with binary/text strings */
  271. #define TEXT_TYPE          1
  272. #define COMMENT_TYPE       2
  273. #define DIR_TYPE           3
  274. #define LABEL_TYPE         4
  275.  
  276. #define GARBLE_FLAG     0x01
  277. #define VOLUME_FLAG     0x04
  278. #define EXTFILE_FLAG    0x08
  279. #define PATHSYM_FLAG    0x10
  280.  
  281. typedef ulong UCRC;     /* CRC-32 */
  282.  
  283. #define CRC_MASK        0xFFFFFFFFL
  284.  
  285. #define ARJ_PATH_CHAR   '/'
  286.  
  287. #define FA_RDONLY       0x01            /* Read only attribute */
  288. #define FA_HIDDEN       0x02            /* Hidden file */
  289. #define FA_SYSTEM       0x04            /* System file */
  290. #define FA_LABEL        0x08            /* Volume label */
  291. #define FA_DIREC        0x10            /* Directory */
  292. #define FA_ARCH         0x20            /* Archive */
  293.  
  294. #define HOST_OS_NAMES1 "MS-DOS","PRIMOS","UNIX","AMIGA","MAC-OS","OS/2"
  295. #define HOST_OS_NAMES2 "APPLE GS","ATARI ST","NEXT","VAX VMS"
  296. #define HOST_OS_NAMES  { HOST_OS_NAMES1, HOST_OS_NAMES2, NULL }
  297.  
  298. /* Timestamp macros */
  299.  
  300. #define get_tx(m,d,h,n) (((ulong)m<<21)+((ulong)d<<16)+((ulong)h<<11)+(n<<5))
  301. #define get_tstamp(y,m,d,h,n,s) ((((ulong)(y-1980))<<25)+get_tx(m,d,h,n)+(s/2))
  302.  
  303. #define ts_year(ts)  ((uint)((ts >> 25) & 0x7f) + 1980)
  304. #define ts_month(ts) ((uint)(ts >> 21) & 0x0f)      /* 1..12 means Jan..Dec */
  305. #define ts_day(ts)   ((uint)(ts >> 16) & 0x1f)      /* 1..31 means 1st..31st */
  306. #define ts_hour(ts)  ((uint)(ts >> 11) & 0x1f)
  307. #define ts_min(ts)   ((uint)(ts >> 5) & 0x3f)
  308. #define ts_sec(ts)   ((uint)((ts & 0x1f) * 2))
  309.  
  310. /* unarj.c */
  311.  
  312. extern long origsize;
  313. extern long compsize;
  314.  
  315. extern UCRC crc;
  316.  
  317. extern FILE *arcfile;
  318. extern FILE *outfile;
  319.  
  320. extern ushort bitbuf;
  321.  
  322. extern uchar subbitbuf;
  323. extern uchar header[HEADERSIZE_MAX];
  324.  
  325. extern char arc_name[FNAME_MAX];
  326.  
  327. extern int bitcount;
  328. extern int file_type;
  329. extern int error_count;
  330.  
  331. /* Global functions */
  332.  
  333. /* unarj.c */
  334.  
  335. void   strlower OF((char *str));
  336. void   strupper OF((char *str));
  337. voidp  *malloc_msg OF((int size));
  338. void   disp_clock OF((void));
  339. void   error OF((char *fmt, char *arg));
  340. void   fillbuf OF((int n));
  341. ushort getbits OF((int n));
  342. void   fwrite_txt_crc OF((uchar *p, int n));
  343. void   init_getbits OF((void));
  344.  
  345. /* environ.c */
  346.  
  347. FILE   *file_open OF((char *name, char *mode));
  348. int    file_read OF((char *buf, int size, int nitems, FILE *stream));
  349. int    file_seek OF((FILE *stream, long offset, int mode));
  350. long   file_tell OF((FILE *stream));
  351. int    file_write OF((char *buf, int size, int nitems, FILE *stream));
  352. voidp  *xmalloc OF((int size));
  353. void   case_path OF((char *name));
  354. void   default_case_path OF((char *name));
  355. int    file_exists OF((char *name));
  356. void   get_mode_str OF((char *str, uint fmode));
  357. int    set_ftime_mode OF((char *name, ulong timestamp, uint fmode, uint host));
  358.  
  359. /* decode.c */
  360.  
  361. void    decode OF((void));
  362. void    decode_f OF((void));
  363.  
  364. /* Message strings */
  365.  
  366. extern char M_VERSION [];
  367.  
  368. extern char M_ARCDATE [];
  369. extern char M_BADCOMND[];
  370. extern char M_BADCOMNT[];
  371. extern char M_BADHEADR[];
  372. extern char M_BADTABLE[];
  373. extern char M_CANTOPEN[];
  374. extern char M_CANTREAD[];
  375. extern char M_CANTWRIT[];
  376. extern char M_CRCERROR[];
  377. extern char M_CRCOK   [];
  378. extern char M_DIFFHOST[];
  379. extern char M_ENCRYPT [];
  380. extern char M_ERRORCNT[];
  381. extern char M_EXTRACT [];
  382. extern char M_FEXISTS [];
  383. extern char M_HEADRCRC[];
  384. extern char M_NBRFILES[];
  385. extern char M_NOMEMORY[];
  386. extern char M_NOTARJ  [];
  387. extern char M_PROCARC [];
  388. extern char M_SKIPPED [];
  389. extern char M_SUFFIX  [];
  390. extern char M_TESTING [];
  391. extern char M_UNKNMETH[];
  392. extern char M_UNKNTYPE[];
  393. extern char M_UNKNVERS[];
  394.  
  395. #endif
  396.  
  397. /* end UNARJ.H */
  398.